Hi Expert,
I want to perform a AJAX request in a function and then return the result of the request (using mootools). The request and the response are working like I want, but the variable is still 0.
here my function:
function recalcPrice(baseprice, rclass, count){
var newPrice = 0;
var request = new Request.JSON({
method: 'post',
url: 'controller/xhr_request.php',
async: false, //UPDATE: that line solves the problem
data: {
'performaction' : 'calcNumberPrice',
'baseprice' : baseprice,
'class' : class,
'number' : count
},
timeout : 5000,
onComplete: function(response) {
console.log('response=' + response);
if(response.status == 'success'){
console.log('price = ' + response.price);
newPrice = response.price;
}
}
});
request.send();
return newPrice;
}
console shows that the price has calculated correctly, but the variable newPrice is not changed...
The problem is allready known in SO but shouldn't this solution made it?
Any help on above is really appreciated.
set value out of mootools request
215020-Jun-2013
Sumit Kesarwani
20-Jun-2013